'use strict';
/**
 * create constant
 */
var util = require('util');
var path = require('path');
var ScriptBase = require('../../lib/script-base');
var nbPreference = require('../../lib/nb-preference');

/**
 * Constructor
 */
var Generator = module.exports = function()
{
    ScriptBase.apply(this , arguments);
    // setup the placeholder
    this.constantAnswers = {};

};

util.inherits(Generator , ScriptBase);

/**
 * this kicks in when they init with interactive mode
 */
Generator.prototype.askForConstant = function(cb)
{
    if (this.interactive) {
        cb = cb || this.async();
		this.prompt({
			type: 'input',
			message: (self.lang==='en') ? 'Constant Name' : '常数名字',
			name: 'constantName'
		}, function(props)
		{
			this.constantAnswers[props.constantName] = '';
			this._askForConstantValue(cb , props.constantName);
		}.bind(this));
    }
};

/**
 * ask for the value
 */
Generator.prototype._askForConstantValue = function(cb , constantName)
{
    this.prompt({
        type: 'input',
        message: (self.lang==='en') ? 'Constant `' + constantName + '` value': '常数`' + constantName + '`值',
        name: 'constantValue'
    }. function(props) {
        this.constantAnswers[constantName] = props.constantValue;
        this._askIfContinue(cb);
    }.bind(this));
};

/**
 * ask if continue
 */
Generator.prototype._askIfContinue = function(cb)
{
    this.prompt({
        type: 'confirm',
        message: (self.lang==='en') ? 'Continue?' : '继续?',
        name: 'cont',
        default: true
    }, function(props)
    {
        if (props.cont) {
            this.askForConstant(cb);
        }
        else {
            cb();
        }
    }.bind(this));
};

/**
 * createing files
 */
Generator.prototype.createConstantFile = function()
{
    this.appConstants = JSON.stringify(this.constantAnswers , null , 4);

    this.appTemplate('constant', path.join('scripts' , 'constants' , this.name));

};
